package com.lk.springboot.controller;

import com.alibaba.fastjson.JSON;
import com.lk.springboot.vo.Result;
import com.lk.springboot.vo.ResultCode;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lk
 * @description: 统一错误页面处理
 */
@RestController
public class CommonErrorController implements ErrorController {

    private final String ERROR_PATH = "/error";

    @Override
    public String getErrorPath() {
        return ERROR_PATH;
    }

    @RequestMapping(value = ERROR_PATH)
    public String handleError() {
        Result result = new Result(ResultCode.UNEXPECTED_ERROR);
        result.setData("对不起，发生系统错误，请联系管理员或稍后再试");
        return JSON.toJSONString(result);
    }
}